package com.linln.admin.bank.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.linln.admin.core.enums.StatusEnum;
import com.linln.admin.system.domain.File;
import com.linln.admin.system.domain.User;

import lombok.Data;

/**
 * @author kome
 * @date 2020/08/08
 */
@Entity
@Table(name = "biz_clue")
@Data
@EntityListeners(AuditingEntityListener.class)
public class Clue implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long      id;
    // 手机号
    private String    phone;
    // 昵称
    private String    nick;
    // 创建时间
    @CreatedDate
    private Date      createDate;
    // 更新时间
    @LastModifiedDate
    private Date      updateDate;
    // 机构代码
    private String    orgCode;
    // 机构名称
    private String    orgName;
    // 姓名
    private String    name;
    // 性别
    private Byte      sex;
    // 证件类型
    private Byte      idType;
    // 证件号
    private String    idNo;
    // 分配人
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "assign_by")
    private User      assignBy;
    // 分配时间
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date      assignTime;
    // 分配状态
    private Byte      assignStatus;
    // 分配备注
    private String    assignNote;
    // 完善人
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "complete_by")
    private User      completeBy;
    // 完善时间
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date      completeTime;
    // 完善状态
    private Byte      completeStatus;
    // 完善备注
    private String    completeNote;
    // 分派人
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "allot_by")
    private User      allotBy;
    // 分派时间
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date      allotTime;
    // 分派状态
    private Byte      allotStatus;
    // 分派备注
    private String    allotNote;
    // 审核人
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "auth_by")
    private User      authBy;
    // 审核时间
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date      authTime;
    // 审核状态
    private Byte      authStatus;
    // 审核备注
    private String    authNote;
    // 通知人
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "notify_by")
    private User      notifyBy;
    // 通知时间
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date      notifyTime;
    // 通知状态
    private Byte      notifyStatus;
    // 通知备注
    private String    notifyNote;
    // 状态
    private Byte      status = StatusEnum.OK.getCode();
    // 创建人
    @CreatedBy
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "create_by")
    @JsonIgnore
    private User      createBy;
    // 更新人
    @LastModifiedBy
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "update_by")
    @JsonIgnore
    private User      updateBy;

    @OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST })
    @JoinTable(name = "biz_clue_file", joinColumns = @JoinColumn(name = "clue_id"), inverseJoinColumns = @JoinColumn(name = "file_id"))
    @JsonIgnore
    private Set<File> files  = new HashSet<>(0);
}
